﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class con_allcomm : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
{
        DBaccess db = new DBaccess();
        DataSet ds = new DataSet();
        String rid = HttpContext.Current.Request.QueryString["rid"];
        if(rid == null) rid = "13";
        int i;
        String sql = "select top " + Label1.Text.ToString() + " * from mr_v_comment where rid = '" + rid + "' order by time desc";
        ds = db.GetDataSet(sql);
        for (i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            con_comment c = (con_comment)Page.LoadControl("~/Controls/con_comment.ascx");
            c.SetComment(ds.Tables[0].Rows[i]["logo"].ToString(), ds.Tables[0].Rows[i]["mname"].ToString(), ((DateTime)ds.Tables[0].Rows[i]["time"]).ToShortDateString(), ds.Tables[0].Rows[i]["comment"].ToString());
            PanelComment.Controls.Add(c);
        }
    }

    protected void ButtonMore_Click(object sender, EventArgs e)
    {
        DBaccess db = new DBaccess();
        DataSet ds = new DataSet();
        int m = Int16.Parse(Label1.Text.ToString());
        String rid = HttpContext.Current.Request.QueryString["rid"];
        if (rid == null) rid = "13";
        Label1.Text = (m + 2).ToString();
        String sql = "SELECT TOP 2 * FROM  mr_v_comment a WHERE Not Exists (Select * From (select top " + m + " * from mr_v_comment where rid = '" + rid + "' order by time desc) b Where b.sid=a.sid and  b.rid = a.rid and b.time = a. time ) and rid = '" + rid + "' Order by time desc";
        ds = db.GetDataSet(sql);
        int i = 0;
        for (i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            con_comment c = (con_comment)Page.LoadControl("~/Controls/con_comment.ascx");
            c.SetComment(ds.Tables[0].Rows[i]["logo"].ToString(), ds.Tables[0].Rows[i]["mname"].ToString(), ((DateTime)ds.Tables[0].Rows[i]["time"]).ToLongDateString(), ds.Tables[0].Rows[i]["comment"].ToString());
            PanelComment.Controls.Add(c);
        }
        if (i == 0)
        {
            ButtonMore.Enabled = false;
            ButtonMore.Text = "无更多评论";
        }
    }
}